package com.assessment.controller;

import com.assessment.service.DownLoadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static com.assessment.utils.ReturnMap.failedMap;

@RestController
@CrossOrigin("*")
@RequestMapping("/admin/download")
public class DownloadController {
    private static final Logger log = LoggerFactory.getLogger(DownloadController.class);
    @Autowired(required = false)
    DownLoadService downLoadService;
    // 获取所有列表
    @GetMapping("/{fileFolder}/{fileName}")
    public ResponseEntity<Object> getFile(@PathVariable("fileFolder") String fileFolder, @PathVariable("fileName") String fileName) {
        log.info("filenAme:{}", fileName);
        try {
            return downLoadService.getFile(fileFolder,fileName);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseEntity<>(failedMap("文件不存在"), HttpStatus.OK);
        }
    }
}
